﻿<!DOCTYPE html>

<html xmlns:th="http://www.thymeleaf.org">
<HEAD>
    <META content="IE=11.0000" http-equiv="X-UA-Compatible">
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <TITLE>发布新投票</TITLE>
    <LINK href="/vote/css/style.css" rel="stylesheet" type="text/css">
    <SCRIPT src="jquery-1.8.3.min.js" type="text/javascript"></SCRIPT>
    <SCRIPT type="text/javascript">
        $(function () {
            $(".del").click(function () {
                $(this).parent().remove();
            });
        });
        function AddOption() {
            var str="<p><INPUT name=\"options\" class=\"input-text\" type=\"text\" onblur='item(this)'><span onclick='del(this)'>删除</span></p>";
            $("#voteoptions").append(str);
        }

        function del(aa) {
            $(aa).parent().remove();
        }

        function vote() {
            var title=$("#title").val();

            $.post("pdSubject",{"title":title},function (result) {

                if(!result){
                    $("#pd").text("该标题已存在");
                    return result;
                }
                return result;
            },"json");
        }
        function item(it) {
            var num=0;
            var item=$(it).val();
            var items = new Array();
            $(".input-text").each(function(index, el) {
                items[index] = el.value;
            });
            for (var i=0;i<items.length;i++){
                if(items[i]==item){
                    num++;
                }
            }
            if(num>1){
                $(it).val("");
            }
        }
    </SCRIPT>
    <META name="GENERATOR" content="MSHTML 11.00.10586.420">
</HEAD>
<BODY>
<DIV class="wrap" id="header"><IMG src="/vote/images/logo.gif"></DIV>
<DIV class="wrap" id="navbar">
    <DIV class="profile">您好,<span th:text="${session.user}"></span>
        <SPAN class="return"><A href="/vote/show/1/null">返回列表</A></SPAN>
        <SPAN class="addnew"><A href="/vote/ad" th:if="${session.user=='admin'?true:false}">添加新投票</A></SPAN>
        <SPAN class="modify"><A id="tain" th:if="${session.user=='admin'?true:false}">维护</A></SPAN>
        <SPAN class="return"><A href="/vote/cancellation">注销</A></SPAN></DIV>

</DIV>
<DIV class="box" id="voteManage">
    <H2>添加新投票</H2>
    <DIV class="content">
        <FORM action="/vote/addvote" method="post">
            <DL>
                <DT>投票内容：</DT>
                <DD>
                    <INPUT name="struts.token.name" type="hidden" value="token">
                    <INPUT name="token" type="hidden" value="B1XPKLEQ7DQ6DNVWKBARPOY4HLYYXDE6">
                    <INPUT name="title" onblur="vote()" class="input-text" id="title" type="text"><span id="pd"></span>
                </DD>
                <DT>投票类型：</DT>
                <DD>
                    <INPUT name="type" type="radio" value="1">单选
                    <INPUT name="type" type="radio" value="0">多选
                </DD>
                <DT>投票选项：</DT>
                <DD id="voteoptions">
                    <P><INPUT name="options" class="input-text" onblur="item(this)" type="text"></P>
                    <P><INPUT name="options" class="input-text" onblur="item(this)" type="text"></P>

                </DD>
                <DT></DT>
                <DD class="button">
                    <INPUT type="image" src="/vote/images/button_submit.gif">
                    <A onclick="AddOption()" href="javascript:0;">增加选项</A>
                    <A href="/vote/show/1/null">取消操作</A>
                    <span th:text="${pd}"></span>
                </DD>
            </DL>
        </FORM>
    </DIV>
</DIV>
<DIV class="wrap" id="footer"> 北大青鸟 © 版权所有</DIV>
</BODY>
</HTML>
